package util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexJudge {

	/**
	 * 判断一个字符串是不是一个表示年份的数
	 * */
	public static boolean isYear(String str){
	    String regEx = "\\d{4}";
	    Pattern pattern = Pattern.compile(regEx);
	    Matcher matcher = pattern.matcher(str);
	    boolean rs = matcher.matches();
	    if(!rs){ // 不是4位数字
	    	return false;
	    }else{
	    	int year = Integer.parseInt(str);
	    	if(year>2016){
	    		return false;
	    	}
	    }
	    
	    return rs;
	}
	
	/**
	 * 判断一个字符串是不是包含字母
	 * */
	public static boolean containChar(String str){
	    String regEx = "[a-zA-Z]";
	    Pattern pattern = Pattern.compile(regEx);
	    Matcher matcher = pattern.matcher(str);
	    boolean rs = matcher.find();
	    return rs;
	}
	
	/**
	 * 判断一个字符串是不是全是汉字
	 * */
	public static boolean isChinese(String str){
	    String regEx = "^[\u4e00-\u9fa5]+$";
	    Pattern pattern = Pattern.compile(regEx);
	    Matcher matcher = pattern.matcher(str);
	    boolean rs = matcher.matches();
	    return rs;
	}

	/**
	 * 判断一个字符串是不是全是数字
	 * */
	public static boolean isNumber(String str){
		String regEx = "^[0-9]+$";
		Pattern pattern = Pattern.compile(regEx);
		Matcher matcher = pattern.matcher(str);
		boolean rs = matcher.matches();
		return rs;
	}
	
	
	public static void main(String[] args) {


		String str = "5345";

		System.out.println(isNumber(str));

	}
	
	
}
